/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aletex.entity;

import java.io.Serializable;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author cibervn
 */
@Entity
@Table(name = "p_rolepermission")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "RolePermission.findAll", query = "SELECT r FROM RolePermission r"),
    @NamedQuery(name = "RolePermission.findByRoleID", query = "SELECT r FROM RolePermission r WHERE r.rolePermissionPK.roleID = :roleID"),
    @NamedQuery(name = "RolePermission.findByPermissionID", query = "SELECT r FROM RolePermission r WHERE r.rolePermissionPK.permissionID = :permissionID"),
    @NamedQuery(name = "RolePermission.findByObjectID", query = "SELECT r FROM RolePermission r WHERE r.rolePermissionPK.objectID = :objectID"),
    @NamedQuery(name = "RolePermission.findByStatus", query = "SELECT r FROM RolePermission r WHERE r.status = :status")})
public class RolePermission implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected RolePermissionPK rolePermissionPK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "Status")
    private char status;
    @JoinColumn(name = "ObjectID", referencedColumnName = "ObjectID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private PrivelegedObject privelegedObject;
    @JoinColumn(name = "PermissionID", referencedColumnName = "PermissionID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Permission permission;
    @JoinColumn(name = "RoleID", referencedColumnName = "RoleID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Role role;

    public RolePermission() {
    }

    public RolePermission(RolePermissionPK rolePermissionPK) {
        this.rolePermissionPK = rolePermissionPK;
    }

    public RolePermission(RolePermissionPK rolePermissionPK, char status) {
        this.rolePermissionPK = rolePermissionPK;
        this.status = status;
    }

    public RolePermission(int roleID, int permissionID, int objectID) {
        this.rolePermissionPK = new RolePermissionPK(roleID, permissionID, objectID);
    }

    public RolePermissionPK getRolePermissionPK() {
        return rolePermissionPK;
    }

    public void setRolePermissionPK(RolePermissionPK rolePermissionPK) {
        this.rolePermissionPK = rolePermissionPK;
    }

    public char getStatus() {
        return status;
    }

    public void setStatus(char status) {
        this.status = status;
    }

    public PrivelegedObject getPrivelegedObject() {
        return privelegedObject;
    }

    public void setPrivelegedObject(PrivelegedObject privelegedObject) {
        this.privelegedObject = privelegedObject;
    }

    public Permission getPermission() {
        return permission;
    }

    public void setPermission(Permission permission) {
        this.permission = permission;
    }

    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (rolePermissionPK != null ? rolePermissionPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof RolePermission)) {
            return false;
        }
        RolePermission other = (RolePermission) object;
        if ((this.rolePermissionPK == null && other.rolePermissionPK != null) || (this.rolePermissionPK != null && !this.rolePermissionPK.equals(other.rolePermissionPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "aletex.entity.RolePermission[ rolePermissionPK=" + rolePermissionPK + " ]";
    }
    
}
